//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
// 限制库存
var kuCunReset = '';
// 限购数
var purChasing = '';
// 是否锁定库存/是否限购
var isLockgoodsstocknum = '0';
var isOpenlimitbuy = '0';
var disabled1 = true;
var disabled2 = true;
var isChecked1 = false;
var isChecked2 = false;
var date = '';
var OpenLimitBuyStatus = '0';
Page({
  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: baseJs.imgUrl,
    uid: "",
    homeZindex: 6,
    modalOneZindex: 5,
    modalTwoZindex: 4,
    TypePageZindex: 3,
    duiHuanZindex: 2,
    addDuHuanZindex: 1,
    addModalPageZindex: 0,
    updateModalPageZindex: -1,
    updateDuHuanZindex: -2,
    modalParentArr: [],
    // 选择好的规格父级
    modalAlready: [],
    edictModalArr: [],
    topId: 0,
    //  上传产品时候产品名称、描述字段
    goodsName: "",
    goodsDescribe: "",
    goodsModal: "",
    goodskucun: '',
    // 上传产品时候商品类型字段
    firstId: 1,
    secondId: 1,
    thirdId: "",
    firstName: "医药健康",
    goodsTypeValue: "",
    // 左侧数据
    leftData: [],
    // 右侧数据
    rightData: [],
    topData: [{
      value: "易商品",
      topId: 0,
      leftId: 1,
      active: true
    },
    {
      value: "易服务",
      topId: 1,
      leftId: 27,
      active: false
    },

    ],
    // 上传图片
    base64: "",
    imgList: [],
    imgStr: "",
    // 发货方式
    goodsStyle: ['邮寄发货', '现场兑换', '全部',],
    // 上传产品时候邮寄字段
    styleId: "",
    fixedFee: "",
    fixedNum: "",
    moreFee: "",
    //兑换地址列表
    duiHuanList: [],
    // 上传产品时候兑换地址字段
    duiHuanAddress: "",
    duiHuanPhone: "",
    duiHuanTime: "",
    duiHuanStart: "",
    duiHuanEnd: "",
    // 商品图片
    goodsImages: "",
    // IsBigGoods
    isBigGoods: 0,
    backMaRate: 5,
    isGift: "",
    giftEachTotle: "",
    // 省市区
    addressValue: "",
    region: ['', '', ''],
    // 批量编辑价格
    piLiangFlag: 0,
    piLiangValue: "批量编辑",
    // 最终规格字符串
    modalStr: "",
    modalStrValue: "",
    // 新建规格
    addDialogFlag: true,
    addName: "",
    addListItem: "",
    addList: [],
    // 
    updateIndex: "",
    updateDialogFlag: true,
    updateName: "",
    updateListItem: "",
    updateList: [],
    // 修改兑换地址
    updateDuHuanId: "",
    updateRegion: ['', '', ''],
    updateAddressValue: "",
    updateAddress: "",
    updatePhone: "",
    updateWeek: "",
    updateMorning: "",
    updateAfternoon: "",
    // 
    goodsPrice: "",
    goodsBuluoPrice: "",
    goodsKuCun: "",
    // 是修改还是新增
    addOrUpdate: "",
    uploadOrSave: "上传产品",
    goodsId: "",
    // 
    morningTime: "",
    afternoonTime: "",
    // 选择工作日
    workDaysFlag: true,
    disabled: {
      type: "",
      value: "",
    },
    // 自编码
    hiddensubmit: true,
    nocancel: false,

    // modal提示框
    hiddensubmit1: false,

    // 自编码
    barcode: "",
    // time: "",
    // 日期
    date: '',
    fFlag: true,
    disabled: {
      type: "",
      value: "",
    },
    typeid: 0,
  },


  onLoad: function (options) {
    // console.log(options);
    var that = this;
    var addOrUpdate = this.data.addOrUpdate;
    addOrUpdate = options.addOrUpdate;
    this.setData({
      uid: wx.getStorageSync('uid'),
      addOrUpdate: addOrUpdate,
      goodsId: options.goodsId,
      disabled1: disabled1,
      disabled2: disabled2,
      isChecked1: isChecked1,
      isChecked2: isChecked2,
      typeid: options.typeid
    })
    if (addOrUpdate == "update") {
      this.GetLoadGoodsInfo();
      this.setData({
        uploadOrSave: "保存修改"
      })
    }
    this.GetGoodsType();
    this.GetGoodsTypeSecond();
    this.modalParent();
    this.GetExchangeList();
    this.CheckBusinessIsOpenLimitBuy();
  },
  // 检查商户是否开启限购
  CheckBusinessIsOpenLimitBuy: function (e) {
    var that = this;
    var uid = this.data.uid;
    console.log(baseJs.api_Utils + "CheckBusinessIsOpenLimitBuy" + "?" + "UID=" + uid)
    wx.request({
      url: baseJs.api_Utils + "CheckBusinessIsOpenLimitBuy" + "?" + "UID=" + uid,
      success: function (res) {
        console.log(res.data)
        var json = res.data.ResultData;
        OpenLimitBuyStatus = json.OpenLimitBuyStatus;
        that.setData({
          OpenLimitBuyStatus: OpenLimitBuyStatus,
        })
        // console.log(json);
      }
    })
  },

  // chooseImg
  chooseImg: function (e) {
    var that = this;
    var base64 = this.data.base64;
    var imgSrc = this.data.imgSrc;
    var imgUrl = this.data.imgUrl;
    var imgList = this.data.imgList;
    console.log(imgList);
    wx.chooseImage({
      // 最多可以选择的图片张数，默认9
      count: 9,
      // 可以指定是原图还是压缩图，默认二者都有
      sizeType: ['original', 'compressed'],
      // 可以指定来源是相册还是相机，默认二者都有
      sourceType: ['album', 'camera'],
      success: function (res) {
        console.log(res);
      
        that.setData({
          imgList: res.tempFilePaths,
        })
        console.log(imgList);
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        // var tempFilePaths = res.tempFilePaths[0];
        // base64 = wx.arrayBufferToBase64(res.data);
        wx.getFileSystemManager().readFile({
          filePath: res.tempFilePaths[0], //选择图片返回的相对路径
          encoding: 'base64', //编码格式
          success: res => { //成功的回调
            console.log(res);
            // console.log('data:image/png;base64,' + res.data)
            wx.request({
              url: baseJs.api + baseJs.encryUrl("method=LoadPic"),
              header: {
                "Content-Type": "application/x-www-form-urlencoded"
              },
              method: 'post',
              data: baseJs.json2Form({
                HeadImage: res.data,
                type: 2,
              }),
              success: function (res) {
                console.log(res);
                imgList.push(imgUrl + res.data.ResultData);
                that.setData({
                  imgList: imgList,
                })
              }
            })
          }
        })
      }
    })
  },
  // chooseGoodsType商品类型
  chooseGoodsType: function () {
    this.setData({
      goodsTypeTop: "0"
    })
  },
  // 自编码--modal弹框
  ziBianMa(e) {
    console.log(e)
    var that = this;
    // var id = e.currentTarget.dataset.id;
    var hiddensubmit = this.data.hiddensubmit;
    that.setData({
      hiddensubmit: !this.data.hiddensubmit,
    })
  },
  // 获取自编码
  goodsBarcode: function (e) {
    console.log(e.detail.value)
    this.setData({
      barcode: e.detail.value,
    })
  },

  // 弹框-取消
  cancel: function () {
    this.setData({
      hiddensubmit: true
    });
  },
  // 弹框-确定----生成条码
  confirm: function (e) {
    var that = this;
    var uid = this.data.uid;
    var firstId = this.data.firstId;
    var secondId = this.data.secondId;
    var thirdId = this.data.thirdId;
    var barcode = this.data.barcode;
    console.log(baseJs.api_Utils + "GetGoodsSelfLabelCode/" + "?" + "GTID=" + firstId + "&SecondGTID=" + secondId + "&ThreeGTID=" + thirdId)
    wx.request({
      url: baseJs.api_Utils + "GetGoodsSelfLabelCode/" + "?" + "GTID=" + firstId + "&SecondGTID=" + secondId + "&ThreeGTID=" + thirdId,
      success: function (res) {
        console.log(res.data)
        var json = res.data.ResultData;
        // console.log(json);
        if (res.data.ResultFlag == 1) {
          wx.showToast({
            title: res.data.ResultMsg,
            icon: 'none',
            duration: 2000
          });
        }
        if (res.data.ResultFlag == 0) {
          wx.showToast({
            title: res.data.ResultMsg,
            icon: 'none',
            duration: 2000
          });
        }
        that.setData({
          barcode: res.data.ResultData
        });
      }
    })
    this.setData({
      hiddensubmit: true
    });
  },
  // 扫一扫
  scanTap: function () {
    var that = this;
    var uid = this.data.uid;
    var barcode = this.data.barcode;
    // 扫一扫判断是否登录
    if (!uid) {
      wx.redirectTo({
        url: '/packageA/login/login',
      })
    }
    wx.scanCode({
      success(res) {
        // console.log(res);
        var barcode = res.result;
        // console.log(barcode)
        that.setData({
          barcode: barcode
        })
      },
    })
  },

  // 库存重置量-获取
  ResetInput: function (e) {
    console.log(e)
    this.setData({
      kuCunReset: e.detail.value,
    })
  },
  // 限购-获取
  purChasingInput: function (e) {
    console.log(e)
    this.setData({
      purChasing: e.detail.value,
    })
  },
  // 库存每日重置
  changeSwitch1: function (e) {
    console.log('switch1', e.detail.value)
    var isChecked1 = this.data.isChecked1;
    if (e.detail.value == true) {
      wx.showModal({
        title: '开启库存每日重置',
        content: '库存每日重置的设置开启后，产品的库存每天都会重置为已设置的数量。',
        showCancel: false
      })
      this.setData({
        // isChecked1: false,
        disabled1: false,

      });
      isLockgoodsstocknum = '1';
      console.log(isLockgoodsstocknum)
    } else {
      this.setData({
        // isChecked1: true,     
        disabled1: true,
        kuCunReset: '',
      });
      isLockgoodsstocknum = '0';
      console.log(isLockgoodsstocknum)
    }
  },
  // 限购/人/天
  changeSwitch2: function (e) {
    if (e.detail.value == true) {
      wx.showModal({
        title: '限购设置',
        content: '开启限购设置后，单人单天可购买本产品的数量不超过已设定值。',
        showCancel: false
      })
      this.setData({
        // isChecked1: false,
        disabled2: false,
      });
      isOpenlimitbuy = '1';
    } else {
      this.setData({
        // isChecked1: true,     
        disabled2: true,
        purChasing: '',
      });
      isOpenlimitbuy = '0';
    }
    // isOpenlimitbuy
  },
  // 上传产品--陈列产品
  endUploadTap: function (e) {
    var that = this;
    var uid = this.data.uid;
    var goodsName = this.data.goodsName;
    var goodsDescribe = this.data.goodsDescribe;
    var imgList = this.data.imgList;
    var imgStr = imgList.join(';');
    var modalStr = this.data.modalStr;
    var edictModalArr = this.data.edictModalArr;
    var firstId = this.data.firstId;
    // var firstId = 26363;
    var secondId = this.data.secondId;
    var thirdId = this.data.thirdId;
    var styleId = this.data.styleId;
    var fixedFee = this.data.fixedFee;
    var fixedNum = this.data.fixedNum;
    var moreFee = this.data.moreFee;
    var duiHuanEnd = this.data.duiHuanEnd;
    var duiHuanStart = this.data.duiHuanStart;
    var duiHuanTime = this.data.duiHuanTime;
    var duiHuanPhone = this.data.duiHuanPhone;
    var duiHuanAddress = this.data.duiHuanAddress;
    var isBigGoods = this.data.isBigGoods;
    var backMaRate = this.data.backMaRate;
    var isGift = this.data.isGift;
    var giftEachTotle = this.data.giftEachTotle;
    var goodsPrice = this.data.goodsPrice;
    var goodsBuluoPrice = this.data.goodsBuluoPrice;
    var goodsKuCun = this.data.goodsKuCun;
    var addOrUpdate = this.data.addOrUpdate;
    var goodsModal = this.data.goodsModal;
    var goodskucun = this.data.goodskucun;
    var barcode = this.data.barcode;
    var kuCunReset = this.data.kuCunReset;
    var purChasing = this.data.purChasing;
    var date = this.data.date;
    var customGoodsTypeId = this.data.typeid
    console.log(customGoodsTypeId);
    if (addOrUpdate == "add") {
      this.setData({
        goodsPrice: goodsPrice,
        goodsBuluoPrice: goodsBuluoPrice,
        goodsKuCun: goodsKuCun,
      })
    }
    // console.log(edictModalArr);
    // console.log(modalStr);
    // 新增还是修改
    var addOrUpdate = this.data.addOrUpdate;
    var goodsId = this.data.goodsId;
    if (addOrUpdate == "update") {
      wx.request({
        url: baseJs.api_Goods + "UpdateGoods",
        method: 'post',
        data: baseJs.json2Form({
          UID: uid,
          GoodsId: goodsId,
          GoodsName: goodsName,
          GoodsDescribe: goodsDescribe,
          Images: imgStr,
          NewModels: '',
          GTID: firstId,
          SecondGTID: secondId,
          ThreeGTID: thirdId,
          GoodsPrice: goodsModal,
          GoodsBuluoPrice: goodsModal,
          StoreNum: goodskucun,
          // StoreNum: goodsKuCun,
          DeliveryType: '1',
          IsSimpleLoad: '1',
          // CustomGoodsTypeId: '0',
          CustomGoodsTypeId: customGoodsTypeId,
          DuihuanAddress: '',
          DuihuanPhone: '',
          DuihuanTime: '',
          StartTime: '',
          EndTime: '',
          SetGoodsNum: fixedNum,
          Youfei: '',
          AddYoufei: '',
          GiftEachTotle: '',
          IsBigGoods: '0',
          IsGift: "",
          BackMaRate: '',
          // 条码
          GoodsLableCode: barcode,
          // 限制库存量
          LockGoodsStockNum: kuCunReset,
          // 限购数
          LimitBuyNum: purChasing,
          // 是否锁定库存
          IsLockGoodsStockNum: isLockgoodsstocknum,
          // 是否限购
          IsOpenLimitBuy: isOpenlimitbuy,
          // 产品到期时间
          ExpirationTime: date,
        }),
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },

        success(res) {
          console.log(res);
          if (res.data.ResultFlag == 1) {
            wx.showToast({
              title: res.data.ResultMsg,
              icon: 'none',
              duration: 2000
            });
            setTimeout(function () {
              wx.navigateBack({
                delta: 1
              })
            }, 1000)
          } else {
            wx.showToast({
              title: res.data.ResultMsg,
              icon: 'none',
              duration: 2000
            });
          }
        }
      })
    } else {
      console.log(customGoodsTypeId);
      console.log(that.data.typeid);
      wx.request({
        url: baseJs.api_Goods + "LoadsGoods",
        method: 'post',
        data: baseJs.json2Form({
          UID: uid,
          // GoodsId: goodsId,
          GoodsName: goodsName,
          GoodsDescribe: goodsDescribe,
          Images: imgStr,
          NewModels: '',
          GTID: firstId,
          SecondGTID: secondId,
          ThreeGTID: thirdId,
          GoodsPrice: goodsModal,
          GoodsBuluoPrice: goodsModal,
          StoreNum: goodskucun,
          // StoreNum: goodsKuCun,
          DeliveryType: '1',
          IsSimpleLoad: '1',
          CustomGoodsTypeId: that.data.typeid,
          // CustomGoodsTypeId: customGoodsTypeId,
          DuihuanAddress: '',
          DuihuanPhone: '',
          DuihuanTime: '',
          StartTime: '',
          EndTime: '',
          SetGoodsNum: fixedNum,
          Youfei: '',
          AddYoufei: '',
          GiftEachTotle: '',
          IsBigGoods: '0',
          IsGift: "",
          BackMaRate: '',
          // 条码
          GoodsLableCode: barcode,
          // 限制库存量
          LockGoodsStockNum: kuCunReset,
          // 限购数
          LimitBuyNum: purChasing,
          // 是否锁定库存
          IsLockGoodsStockNum: isLockgoodsstocknum,
          // 是否限购
          IsOpenLimitBuy: isOpenlimitbuy,
          // 产品到期时间
          ExpirationTime: date,
        }),

        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        success(res) {
          console.log(res);
          if (res.data.ResultFlag == 1) {
            wx.showToast({
              title: res.data.ResultMsg,
              icon: 'none',
              duration: 2000
            });
            setTimeout(function () {
              wx.navigateBack({
                delta: 1
              })
            }, 1000)
          } else {
            wx.showToast({
              title: res.data.ResultMsg,
              icon: 'none',
              duration: 2000
            });
          }

        }
      })
    }
  },

  // 顶部点击
  topTap: function (e) {
    var that = this;
    // console.log(e);
    var topData = this.data.topData;
    var leftData = this.data.leftData;
    var rightData = this.data.rightData;
    var value = e.currentTarget.dataset.value;
    var topId = e.currentTarget.dataset.topid;
    var firstId = e.currentTarget.dataset.leftid;
    for (var i = 0, len = topData.length; i < len; ++i) {
      if (topData[i].value == value) {
        topData[i].active = true;
      } else {
        topData[i].active = false;
      }
    }
    this.setData({
      topData: topData,
      value: value,
      topId: topId,
      firstId: firstId,
    })
    // console.log(topData);
    leftData = [];
    rightData = [];
    this.GetGoodsType();
    this.GetGoodsTypeSecond();
  },
  // 左侧点击
  leftTap: function (e) {
    var that = this;
    // console.log(e);
    var leftData = this.data.leftData;
    var rightData = this.data.rightData;
    var firstName = e.currentTarget.dataset.value;
    var firstId = e.currentTarget.dataset.id;
    for (var i = 0, len = leftData.length; i < len; ++i) {
      if (leftData[i].TypeName == firstName) {
        leftData[i].active = true;
      } else {
        leftData[i].active = false
      }
    }
    this.setData({
      leftData: leftData,
      firstId: firstId,
      firstName: firstName
    })
    rightData = [];
    this.GetGoodsTypeSecond();
  },

  // 易商品、易服务
  GetGoodsType: function () {
    var that = this;
    var topId = this.data.topId;
    var leftData = this.data.leftData;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetGoodsType&GoodsOrService=" + topId),
      success: function (res) {
        leftData = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        for (var i = 0; i < leftData.length; i++) {
          leftData[i].active = false;
          leftData[0].active = true;
        }
        that.setData({
          leftData: leftData,
        })
        // console.log(leftData);
      }
    })
  },
  // 
  GetGoodsTypeSecond: function () {
    var that = this;
    var firstId = this.data.firstId;
    var rightData = this.data.rightData;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetGoodsTypeSecond&OneId=" + firstId),
      success: function (res) {
        rightData = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        // console.log(rightData)
        var arr = [];
        for (var key in rightData) {
          var obj = {
            name: key,
            list: rightData[key]
          };
          arr.push(obj);
        }
        rightData = arr;
        for (var i = 0, len = rightData.length; i < len; i++) {
          for (var j = 0, leng = rightData[i].list.length; j < leng; j++) {
            rightData[i].list[j].name = rightData[i].name;
          }
        }
        that.setData({
          rightData: rightData,
        })
        // console.log(rightData);
      }
    })
  },
  // 删除图片
  delTap: function (e) {
    var imgList = this.data.imgList;
    imgList.splice(e.currentTarget.dataset.index, 1);
    this.setData({
      imgList: imgList,
    })
    console.log(imgList);
  },
  // 选择商品发货方式
  bindPickerChange: function (e) {
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      styleId: e.detail.value,
    })
  },
  // 邮费解释
  feeAlert: function () {
    wx.showModal({
      title: '提示',
      content: '部落内邮费设置分为固定邮费和补充邮费，固定邮费包括邮费额度和包含件数，包含件数内邮费是设置的固定值，补充邮费指的是购买数量超出固定邮费包含的件数后，每件加收的邮费额度!',
      showCancel: false,
      confirmText: "确定",
    })
  },
  // 弹出选择兑换地址
  chooseDuihuan: function () {
    this.setData({
      duiHuanZindex: 9
    })
  },
  // 点击选择兑换地址
  duiHuanAlready: function (e) {
    var index = e.currentTarget.dataset.index;
    // console.log(e);
    this.setData({
      duiHuanAddress: this.data.duiHuanList[index].Province + " " + this.data.duiHuanList[index].city + " " + this.data.duiHuanList[index].Area + " " + this.data.duiHuanList[index].supplyAddress,
      duiHuanPhone: this.data.duiHuanList[index].Phone,
      duiHuanTime: this.data.duiHuanList[index].WeekDay,
      duiHuanStart: this.data.duiHuanList[index].StartTime,
      duiHuanEnd: this.data.duiHuanList[index].EndTime,
      duiHuanZindex: 1
    })
  },
  // 删除兑换地址
  delDuiHuan: function (e) {
    var that = this;
    wx.showModal({
      content: '确认删除该地址？',
      confirmText: "确定",
      cancelText: "取消",
      success: function (res) {
        if (res.confirm) {
          // 点击确定
          wx.request({
            url: baseJs.api + baseJs.encryUrl("method=DeleteExchangeInfo&ExchangeID=" + e.currentTarget.dataset.id),
            success: function (res) {
              var json = JSON.parse(baseJs.decryUrl(res.data));
              if (json.ResultFlag == 1) {
                wx.showToast({
                  title: "删除成功！",
                  icon: 'none',
                  duration: 2000
                });
                that.GetExchangeList();
              }
            }
          })
        } else {
          // 点击取消
        }
      },
    });
  },
  // 修改兑换地址
  updateDuiHuan: function (e) {
    var that = this;
    var updateRegion = this.data.updateRegion;
    var updateDuHuanId = this.data.updateDuHuanId;
    updateDuHuanId = e.currentTarget.dataset.id;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetExchageInfo&ExchangeID=" + e.currentTarget.dataset.id),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data));
        // console.log(json);
        updateRegion[0] = json.ResultData.Province;
        updateRegion[1] = json.ResultData.City;
        updateRegion[2] = json.ResultData.Area;
        if (json.ResultFlag == 1) {
          that.setData({
            updateDuHuanId: updateDuHuanId,
            updateRegion: updateRegion,
            updateAddressValue: json.ResultData.Province + " " + json.ResultData.City + " " + json.ResultData.Area,
            updateAddress: json.ResultData.SupplyAddress,
            updatePhone: json.ResultData.ExchangePhone,
            updateWeek: json.ResultData.WeekDay,
            updateMorning: json.ResultData.StartTime,
            updateAfternoon: json.ResultData.EndTime,
            updateDuHuanZindex: 9,
          })
        }
      }
    })
  },
  // 修改兑换地址省市区
  bindRegionChangeUpdate: function (e) {
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      updateRegion: e.detail.value,
      updateAddressValue: e.detail.value[0] + " " + e.detail.value[1] + " " + e.detail.value[2],
    })
  },
  // 保存修改地址
  updateSubmit: function (e) {
    // console.log(e);
    var that = this;
    var uid = this.data.uid;
    var updateRegion = this.data.updateRegion;
    var updateDuHuanId = this.data.updateDuHuanId;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=UpdateExchanegInfo&UID=" + uid + "&Province=" + updateRegion[0] + "&City=" + updateRegion[1] + "&Area=" + updateRegion[2] + "&SupplyAddress=" + e.detail.value.updateDetailAddress + "&ExchangePhone=" + e.detail.value.updatePhone + "&WeekDay=" + e.detail.value.updateWeek + "&StartTime=" + e.detail.value.updateMorning + "&EndTime=" + e.detail.value.updateAfternoon + "&ExchangeID=" + updateDuHuanId),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data));
        // console.log(json);
        if (json.ResultFlag == 1) {
          wx.showToast({
            title: json.ResultMsg,
            icon: 'none',
            duration: 2000
          });
          that.setData({
            updateDuHuanZindex: -2,
          })
          that.GetExchangeList();
        } else {
          wx.showToast({
            title: json.ResultMsg,
            icon: 'none',
            duration: 2000
          });
        }
      }
    })

  },
  // 取消修改地址
  updateReset: function (e) {
    this.setData({
      updateDuHuanZindex: -2,
    })
  },
  // 固定邮费
  fixedFee: function (e) {
    this.setData({
      fixedFee: e.detail.value
    })
  },
  // 固定件数
  fixedNum: function (e) {
    this.setData({
      fixedNum: e.detail.value
    })
  },
  // 超出邮费
  moreFee: function (e) {
    this.setData({
      moreFee: e.detail.value
    })
  },
  // 显示选择规格父级
  chooseModal: function () {
    this.setData({
      modalOneZindex: 9,
    })
  },
  // 取消选择规格父级
  cancelChooseModal: function () {
    this.setData({
      modalOneZindex: 2,
    })
  },
  // 新建规格父级
  createNewModal: function () {
    this.setData({
      addModalPageZindex: 9,
    })
  },
  // 完成选择规格父级
  finishChooseModal: function () {
    if (this.data.modalAlready.length == 0) {
      wx.showModal({
        content: '请选择规格!',
        confirmText: "确定",
        showCancel: false,
      });
      return false;
    }
    this.setData({
      modalTwoZindex: 9,
    })
    // console.log(this.data.modalAlready)
  },
  // 显示选择商品分类
  chooseGoodsType: function () {
    this.setData({
      TypePageZindex: 9,
    })
  },
  // 取消选择商品分类
  cancelTypePage: function () {
    this.setData({
      TypePageZindex: 1,
    })
  },
  // 完成选择商品分类
  rightTap: function (e) {
    // console.log(e);
    this.setData({
      secondId: e.currentTarget.dataset.secondid,
      thirdId: e.currentTarget.dataset.thirdid,
      secondName: e.currentTarget.dataset.secondname,
      thirdName: e.currentTarget.dataset.thirdname,
      TypePageZindex: 1,
      goodsTypeValue: this.data.firstName + '>' + e.currentTarget.dataset.secondname + '>' + e.currentTarget.dataset.thirdname,
    })
    // console.log(this.data.firstId, this.data.secondId, this.data.thirdId);
  },
  // 规格父级列表
  modalParent: function () {
    var that = this;
    var uid = this.data.uid;
    var modalParentArr = this.data.modalParentArr;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=BusinessGetGoodsSpecificationsAndAttribute&UID=" + uid),
      success: function (res) {
        var str = JSON.parse(baseJs.decryUrl(res.data)).ResultData.TypeNameAndElement;
        var arr1 = str.split(";");
        arr1.forEach((v, i) => {
          var obj = {};
          var obj_arr = [];
          var arr2 = v.split("|");
          obj.name = arr2[0];
          arr2[1].split(",").forEach(v => obj_arr.push({
            name: arr2[0],
            value: v,
            active: false
          }));
          obj.list = obj_arr;

          modalParentArr.push(obj);
        })
        that.setData({
          modalParentArr: modalParentArr,
        })
      }
    })
  },
  //
  checkboxChange: function (e) {
    var that = this;
    var modalParentArr = this.data.modalParentArr;
    var modalAlready = this.data.modalAlready;
    modalAlready = [];
    for (var i = 0; i < e.detail.value.length; i++) {
      modalAlready.push(modalParentArr[e.detail.value[i]]);
    }
    this.setData({
      modalAlready: modalAlready
    })
  },
  // chooseValue
  chooseValue: function (e) {
    var that = this;
    var modalAlready = this.data.modalAlready;
    var edictModalArr = this.data.edictModalArr;
    var name = e.currentTarget.dataset.name;
    var value = e.currentTarget.dataset.value;
    for (var i = 0, len = modalAlready.length; i < len; i++) {
      if (name == modalAlready[i].name) {
        for (var j = 0, leng = modalAlready[i].list.length; j < leng; j++) {
          if (value == modalAlready[i].list[j].value) {
            if (modalAlready[i].list[j].active == false) {
              modalAlready[i].list[j].active = true;
            } else {
              modalAlready[i].list[j].active = false;
            }
          }
        }
      }
    }
    this.setData({
      modalAlready: modalAlready
    })
    edictModalArr = this.arrToSelect(modalAlready);
    this.setData({
      edictModalArr: edictModalArr
    })
    // console.log(edictModalArr);
  },
  // 兑换地址列表
  GetExchangeList: function () {
    var that = this;
    var uid = this.data.uid;
    var duiHuanList = this.data.duiHuanList;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetExchangeList&UID=" + uid),
      success: function (res) {
        duiHuanList = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        that.setData({
          duiHuanList: duiHuanList,
        })
        // console.log(duiHuanList);
      }
    })
  },
  // 添加兑换地址
  addDuiHuan: function () {
    this.setData({
      addDuHuanZindex: 9
    })
  },
  // 省市区
  bindRegionChange: function (e) {
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      region: e.detail.value,
      addressValue: e.detail.value[0] + " " + e.detail.value[1] + " " + e.detail.value[2],
    })
  },
  // 保存添加地址
  addSubmit: function (e) {
    // console.log(e);
    var that = this;
    var uid = this.data.uid;
    var region = this.data.region;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=AddExchangeInfo&UID=" + uid + "&Province=" + region[0] + "&City=" + region[1] + "&Area=" + region[2] + "&SupplyAddress=" + e.detail.value.detailAddress + "&ExchangePhone=" + e.detail.value.phone + "&WeekDay=" + e.detail.value.week + "&StartTime=" + e.detail.value.morning + "&EndTime=" + e.detail.value.afternoon),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data));
        if (json.ResultFlag == 1) {
          wx.showToast({
            title: json.ResultMsg,
            icon: 'none',
            duration: 2000
          });
          that.setData({
            addDuHuanZindex: 1
          })
          that.GetExchangeList();
        } else {
          wx.showToast({
            title: json.ResultMsg,
            icon: 'none',
            duration: 2000
          });
        }
      }
    })

  },
  // 取消添加地址
  addReset: function (e) {
    this.setData({
      addDuHuanZindex: 1
    })
  },
  // 商品名称
  nameInput: function (e) {
    this.setData({
      goodsName: e.detail.value,
    })
  },
  // 产品到期时间
  timeInput: function (e) {
    this.setData({
      date: e.detail.value,
    })
  },
  // 日期选择
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value,
      fFlag: true,
    })
  },

  // 商品名称
  priceInput: function (e) {
    this.setData({
      goodsModal: e.detail.value,
    })
  },
  // 商品库存
  kucunInput: function (e) {
    this.setData({
      goodskucun: e.detail.value,
    })
  },
  // 商品信息描述
  describeInput: function (e) {
    this.setData({
      goodsDescribe: e.detail.value,
    })
  },
  // 商品名称
  price: function (e) {
    console.log(e);
    this.setData({
      goodsModal: e.detail.value,
    })
  },
  // 发货方式、styleId
  // 
  arrToSelect: function (arr) {
    var newArr = [];
    for (var i = 0; i < arr.length; i++) {
      newArr.push([])
      for (var j = 0; j < arr[i].list.length; j++) {
        if (arr[i].list[j].active) {
          newArr[i].push(arr[i].name + "," + arr[i].list[j].value)
        }
      }
    }
    for (var i = 0; i < newArr.length; i++) {
      if (!newArr[i].length) {
        newArr.splice(i, 1);
        i--
      }
    }
    var result;
    for (var i in newArr) {
      result = this.selectResult(result, newArr[i])
    }
    var array = [];
    for (var i in result) {
      array.push({
        value: result[i],
        kuCun: "",
        buLuoPrice: "",
        marketPrice: "",
      })
    }
    return array
  },
  // 
  selectResult: function (result, nextArray) {
    if (result == null || result.length == 0) {
      return nextArray
    }
    var tempResult = [];
    for (var i = 0; i < result.length; i++) {
      for (var j = 0; j < nextArray.length; j++) {
        tempResult.push(result[i] + ";" + nextArray[j])
      }
    }
    return tempResult
  },
  // 市场价格
  marketPrice: function (e) {
    // console.log(e);
    var that = this;
    var edictModalArr = this.data.edictModalArr;
    edictModalArr[e.currentTarget.dataset.index].marketPrice = e.detail.value;
    this.setData({
      edictModalArr: edictModalArr,
    })
  },
  // 部落价格
  buLuoPrice: function (e) {
    var that = this;
    var edictModalArr = this.data.edictModalArr;
    edictModalArr[e.currentTarget.dataset.index].buLuoPrice = e.detail.value;
    this.setData({
      edictModalArr: edictModalArr
    })
  },
  // 库存
  kuCun: function (e) {
    var that = this;
    var edictModalArr = this.data.edictModalArr;
    edictModalArr[e.currentTarget.dataset.index].kuCun = e.detail.value;
    this.setData({
      edictModalArr: edictModalArr
    })
  },
  // 批量编辑
  piLiangTap: function () {
    if (this.data.piLiangFlag == 0) {
      this.setData({
        piLiangFlag: 1,
        piLiangValue: "取消批量编辑"
      })
    } else {
      this.setData({
        piLiangFlag: 0,
        piLiangValue: "批量编辑"
      })
    }
  },
  // 市场价格
  marketPriceAll: function (e) {
    // console.log(e);
    var that = this;
    var edictModalArr = this.data.edictModalArr;
    for (var i = 0; i < edictModalArr.length; i++) {
      edictModalArr[i].marketPrice = e.detail.value;
    }
    this.setData({
      edictModalArr: edictModalArr
    })
    // console.log(this.data.edictModalArr);
  },
  // 部落价格
  buLuoPriceAll: function (e) {
    // console.log(e);
    var that = this;
    var edictModalArr = this.data.edictModalArr;
    for (var i = 0; i < edictModalArr.length; i++) {
      edictModalArr[i].buLuoPrice = e.detail.value;
    }
    this.setData({
      edictModalArr: edictModalArr
    })
    // console.log(this.data.edictModalArr);
  },
  // 库存
  kuCunAll: function (e) {
    // console.log(e);
    var that = this;
    var edictModalArr = this.data.edictModalArr;
    for (var i = 0; i < edictModalArr.length; i++) {
      edictModalArr[i].kuCun = e.detail.value;
    }
    this.setData({
      edictModalArr: edictModalArr
    })
  },
  cancelEdict: function () {
    this.setData({
      modalOneZindex: 9,
      modalTwoZindex: 4,
    })
  },
  finishEdict: function () {
    var that = this;
    var edictModalArr = this.data.edictModalArr;
    var modalStr = this.data.modalStr;
    if (edictModalArr.length == 0) {
      wx.showModal({
        content: '请选择规格！',
        confirmText: "确定",
        showCancel: false,
      });
      return false;
    }
    for (var i = 0; i < edictModalArr.length; i++) {
      if (edictModalArr[i].marketPrice == "" || edictModalArr[i].buLuoPrice == "" || edictModalArr[i].kuCun == "") {
        wx.showModal({
          content: '请完善编辑价格和库存！',
          confirmText: "确定",
          showCancel: false,
          success: function (res) {
            if (res.confirm) {
              // 点击确定

            } else {
              // 点击取消
            }
          },
        });
        return false;
      }
    }
    for (var i = 0; i < edictModalArr.length; i++) {
      // modalStr += edictModalArr[i].value + "-" + edictModalArr[i].marketPrice + "-" + edictModalArr[i].buLuoPrice + "-" + edictModalArr[i].kuCun + "|";
      modalStr += edictModalArr[i].value + "-" + edictModalArr[i].kuCun + "-" + edictModalArr[i].buLuoPrice + "-" + edictModalArr[i].marketPrice + "|";
    }
    modalStr = modalStr.substring(0, modalStr.length - 1);
    this.setData({
      homeZindex: 9,
      modalOneZindex: 5,
      modalTwoZindex: 4,
      modalStr: modalStr,
      modalStrValue: "已编辑"
    })
    // console.log(modalStr);
  },

  // 添加规格父级
  addNameInput: function (e) {
    this.setData({
      addName: e.detail.value,
    })
  },
  // 添加规格类型细分
  addAdd: function () {
    var that = this;
    var addName = this.data.addName;
    var modalParentArr = this.data.modalParentArr;
    // console.log(addName);
    if (addName == "") {
      wx.showModal({
        title: '提示',
        content: '请输入规格类型！',
        showCancel: false,
        confirmText: "确定",
        success: function (res) {
          if (res.confirm) {

          } else {

          }
        },
      })
      return false;
    }
    for (var i = 0; i < modalParentArr.length; i++) {
      if (modalParentArr[i].name == addName) {
        wx.showModal({
          title: '提示',
          content: '该规格已经存在！',
          showCancel: false,
          confirmText: "确定",
          success: function (res) {
            if (res.confirm) {
              that.setData({
                addName: "",
              })

            } else {

            }
          },
        })
        return false;
      }
    }
    this.setData({
      addDialogFlag: false,
    })
  },
  // 
  cancellAdd: function () {
    this.setData({
      addModalPageZindex: 0,
      addName: "",
      addList: [],
    })
  },
  // 
  addFinish: function () {
    var that = this;
    var uid = this.data.uid;
    var addName = this.data.addName;
    var addList = this.data.addList;
    var modalParentArr = this.data.modalParentArr;
    var addNewModalStr = "";
    if (addName == "") {
      wx.showModal({
        title: '提示',
        content: '请输入规格类型！',
        showCancel: false,
        confirmText: "确定",
        success: function (res) {
          if (res.confirm) {

          } else {

          }
        },
      })
      return false;
    }
    if (addList.length == "") {
      wx.showModal({
        title: '提示',
        content: '请添加类型细分！',
        showCancel: false,
        confirmText: "确定",
        success: function (res) {
          if (res.confirm) {

          } else {

          }
        },
      })
      return false;
    }
    modalParentArr.push({
      name: addName,
      list: []
    });
    this.setData({
      modalParentArr: modalParentArr,
    })
    for (var i = 0; i < addList.length; i++) {
      modalParentArr[modalParentArr.length - 1].list.push({
        name: addName,
        active: false,
        value: addList[i]
      });
    }
    // console.log(modalParentArr);
    for (var i = 0; i < modalParentArr.length; i++) {
      addNewModalStr += modalParentArr[i].name + "|";
      for (var j = 0; j < modalParentArr[i].list.length; j++) {
        if (j == modalParentArr[i].list.length - 1) {
          addNewModalStr += modalParentArr[i].list[j].value + ";";
        } else {
          addNewModalStr += modalParentArr[i].list[j].value + ",";
        }
      }
    }
    addNewModalStr = addNewModalStr.substring(0, addNewModalStr.length - 1);
    // console.log(addNewModalStr);
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=BusinessSetGoodsSpecificationsAndAttribute&UID=" + uid + "&TypeInfo=" + addNewModalStr),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data));
        // console.log(json);
        that.setData({
          modalParentArr: modalParentArr,
          addModalPageZindex: 0,
          addName: "",
          addList: [],
        })
      }
    })
  },
  // 
  addDialogCancel: function () {
    this.setData({
      addDialogFlag: true,
      addListItem: "",
    })

  },
  // 
  addDialogConfirm: function () {
    var addList = this.data.addList;
    var addListItem = this.data.addListItem;
    if (addListItem != '') {
      addList.push(addListItem);
    }
    this.setData({
      addDialogFlag: true,
      addListItem: "",
      addList: addList,
    })

  },
  listInput: function (e) {
    if (e.detail.value != '') {
      this.setData({
        addListItem: e.detail.value,
      })
    }
  },
  delListItem: function (e) {
    var addList = this.data.addList;
    addList.splice(e.currentTarget.dataset.index, 1);
    this.setData({
      addList: addList
    })
  },
  // 删除规格
  delModalP: function (e) {
    var that = this;
    var uid = this.data.uid;
    var modalParentArr = this.data.modalParentArr;
    var addNewModalStr = this.data.addNewModalStr;
    var addNewModalStr = "";
    wx.showModal({
      title: '提示',
      content: '是否删除该规格？',
      confirmText: "确定",
      success: function (res) {
        if (res.confirm) {
          wx.request({
            url: baseJs.api + baseJs.encryUrl("method=BusinessDeleteGoodsBigSpecificationsAndAttribute&UID=" + uid + "&Models=" + e.currentTarget.dataset.value),
            success: function (res) {
              var json = JSON.parse(baseJs.decryUrl(res.data));
              // console.log(json);
              if (json.ResultData.IsDelete == '0') {
                wx.showToast({
                  title: "该规格暂不可删除!",
                  icon: 'none',
                  duration: 2000
                });
              } else {
                modalParentArr.splice(e.currentTarget.dataset.index, 1);
                // console.log(modalParentArr);
                for (var i = 0; i < modalParentArr.length; i++) {
                  addNewModalStr += modalParentArr[i].name + "|";
                  // console.log(modalParentArr[i].name);
                  for (var j = 0; j < modalParentArr[i].list.length; j++) {
                    if (j == modalParentArr[i].list.length - 1) {
                      addNewModalStr += modalParentArr[i].list[j].value + ";";
                    } else {
                      addNewModalStr += modalParentArr[i].list[j].value + ",";
                    }
                  }
                }
                addNewModalStr = addNewModalStr.substring(0, addNewModalStr.length - 1);
                // console.log(addNewModalStr);
                wx.request({
                  url: baseJs.api + baseJs.encryUrl("method=BusinessSetGoodsSpecificationsAndAttribute&UID=" + uid + "&TypeInfo=" + addNewModalStr),
                  success: function (res) {
                    var json = JSON.parse(baseJs.decryUrl(res.data));
                    // console.log(json);
                    that.setData({
                      modalParentArr: modalParentArr,
                      addModalPageZindex: 0,
                    })
                  }
                })
                wx.showToast({
                  title: "删除成功!",
                  icon: 'none',
                  duration: 2000
                });
              }
            }
          })
        } else {

        }
      },
    })
  },
  // 修改规格
  updateModalP: function (e) {
    var that = this;
    var updateName = this.data.updateName;
    var updateList = this.data.updateList;
    var modalParentArr = this.data.modalParentArr;
    var updateIndex = this.data.updateIndex;
    for (var i = 0; i < modalParentArr[e.currentTarget.dataset.index].list.length; i++) {
      updateList.push(modalParentArr[e.currentTarget.dataset.index].list[i].value);
    }
    updateName = modalParentArr[e.currentTarget.dataset.index].name;
    modalParentArr[e.currentTarget.dataset.index].list = [];
    updateIndex = e.currentTarget.dataset.index;
    this.setData({
      updateName: updateName,
      updateList: updateList,
      modalParentArr: modalParentArr,
      updateModalPageZindex: 9,
      updateIndex: updateIndex,
    })

  },
  //修改规格，添加细分 
  listUpdateInput: function (e) {
    if (e.detail.value != '') {
      this.setData({
        updateListItem: e.detail.value,
      })
    }

  },
  // 修改规格，取消Dialog
  updateDialogCancel: function () {
    this.setData({
      updateDialogFlag: true,
      updateListItem: "",
    })

  },
  // 修改规格，确定细分Dialog
  updateDialogConfirm: function () {
    var that = this;
    var updateList = this.data.updateList;
    var updateListItem = this.data.updateListItem;
    for (var i = 0; i < updateList.length; i++) {
      if (updateListItem == updateList[i]) {
        wx.showToast({
          title: "该细分类型已存在!",
          icon: 'none',
          duration: 2000
        });
        return false;
      }
    }
    if (updateListItem != '') {
      updateList.push(updateListItem);
    }
    this.setData({
      updateDialogFlag: true,
      updateListItem: "",
      updateList: updateList,
    })

  },
  // 取消修改规格
  cancelUpdate: function () {
    this.setData({
      updateModalPageZindex: -1,
      updateName: "",
      updateList: [],
    })
  },
  addUpdate: function () {
    this.setData({
      updateDialogFlag: false,
    })
  },
  // 
  delUpdateListItem: function (e) {
    // console.log(e);
    var that = this;
    var uid = this.data.uid;
    var updateName = this.data.updateName;
    var updateList = this.data.updateList;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=BusinessDeleteGoodsSpecificationsAndAttribute&UID=" + uid + "&Models=" + updateName + "|" + e.currentTarget.dataset.value),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data));
        // console.log(json);
        if (json.ResultData.IsDelete == '0') {
          wx.showToast({
            title: "该规格暂不可删除!",
            icon: 'none',
            duration: 2000
          });
        } else {
          updateList.splice(e.currentTarget.dataset.index, 1);
          that.setData({
            updateList: updateList
          })

        }
      }
    })
  },
  // 完成修改规格
  finishUpdate: function () {
    var that = this;
    var uid = this.data.uid;
    var updateName = this.data.updateName;
    var updateList = this.data.updateList;
    var modalParentArr = this.data.modalParentArr;
    var updateIndex = this.data.updateIndex;
    var addNewModalStr = "";
    for (var i = 0; i < updateList.length; i++) {
      modalParentArr[updateIndex].list.push({
        name: updateName,
        active: false,
        value: updateList[i]
      });
    }
    for (var i = 0; i < modalParentArr.length; i++) {
      addNewModalStr += modalParentArr[i].name + "|";
      for (var j = 0; j < modalParentArr[i].list.length; j++) {
        if (j == modalParentArr[i].list.length - 1) {
          addNewModalStr += modalParentArr[i].list[j].value + ";";
        } else {
          addNewModalStr += modalParentArr[i].list[j].value + ",";
        }
      }
    }
    addNewModalStr = addNewModalStr.substring(0, addNewModalStr.length - 1);
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=BusinessSetGoodsSpecificationsAndAttribute&UID=" + uid + "&TypeInfo=" + addNewModalStr),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data));
        // console.log(json);
        that.setData({
          updateModalPageZindex: -1,
          updateName: "",
          updateList: [],
          modalParentArr: modalParentArr,
        })
      }
    })
    // console.log(modalParentArr);
  },
  // 得到产品信息--修改
  GetLoadGoodsInfo: function () {
    var that = this;
    var goodsId = this.data.goodsId;
    var uid = this.data.uid;
    var goodsName = this.data.goodsName;
    var goodsDescribe = this.data.goodsDescribe;
    var imgList = this.data.imgList;
    var modalStr = this.data.modalStr;
    var edictModalArr = this.data.edictModalArr;
    var firstId = this.data.firstId;
    var secondId = this.data.secondId;
    var thirdId = this.data.thirdId;
    var styleId = this.data.styleId;
    var fixedFee = this.data.fixedFee;
    var fixedNum = this.data.fixedNum;
    var moreFee = this.data.moreFee;
    var duiHuanEnd = this.data.duiHuanEnd;
    var duiHuanStart = this.data.duiHuanStart;
    var duiHuanTime = this.data.duiHuanTime;
    var duiHuanPhone = this.data.duiHuanPhone;
    var duiHuanAddress = this.data.duiHuanAddress;
    var isBigGoods = this.data.isBigGoods;
    var backMaRate = this.data.backMaRate;
    var isGift = this.data.isGift;
    var giftEachTotle = this.data.giftEachTotle;
    var goodsPrice = this.data.goodsPrice;
    var goodsBuluoPrice = this.data.goodsBuluoPrice;
    var goodsKuCun = this.data.goodsKuCun;
    // var edictModalArr[0].marketPrice;
    var edictModalArr = this.data.edictModalArr;
    var goodsTypeValue = this.data.goodsTypeValue;
    var modalStrValue = this.data.modalStrValue;
    var goodskucun = this.data.goodskucun;
    var barcode = this.data.barcode;
    // var kuCunReset = this.data.kuCunReset;
    // var purChasing = this.data.purChasing;
    var date = this.data.date;
    wx.request({
      url: baseJs.api_Goods + "GetLoadGoodsInfo" + "?" + "GoodsId=" + goodsId,
      success: function (res) {
        var json = res.data;
        console.log(json);
        if (json.ResultFlag == 1) {
          // 
          var imgArr = json.ResultData.Images.split(';');
          for (var i = 0; i < imgArr.length; i++) {
            if (imgArr[i].length > 0) {
              imgList.push(imgArr[i]);
            }
          }
          isLockgoodsstocknum = json.ResultData.IsLockGoodsStockNum;
          isOpenlimitbuy = json.ResultData.IsOpenLimitBuy;
          that.setData({
            goodsName: json.ResultData.GoodsName,
            goodsDescribe: json.ResultData.GoodsDescribe,
            goodsName: json.ResultData.GoodsName,
            imgList: imgList,
            modalStr: json.ResultData.NewModels,
            firstId: json.ResultData.GTID,
            secondId: json.ResultData.SecondGTID,
            thirdId: json.ResultData.ThreeGTID,
            styleId: json.ResultData.DeliveryType,
            fixedFee: parseFloat(json.ResultData.Youfei).toFixed(2),
            fixedNum: parseFloat(json.ResultData.SetGoodsNum).toFixed(0),
            moreFee: parseFloat(json.ResultData.AddYoufei).toFixed(2),
            duiHuanEnd: json.ResultData.EndTime,
            duiHuanStart: json.ResultData.StartTime,
            duiHuanTime: json.ResultData.DuihuanTime,
            duiHuanPhone: json.ResultData.DuihuanPhone,
            duiHuanAddress: json.ResultData.DuihuanAddress,
            isBigGoods: json.ResultData.IsBigGoods,
            backMaRate: json.ResultData.BackMaRate,
            isGift: json.ResultData.IsGift,
            giftEachTotle: json.ResultData.GiftEachTotle,
            goodsTypeValue: json.ResultData.FirstGTIDName + '<' + json.ResultData.SecondGTIDName + "<" + json.ResultData.ThreeGTIDName,
            modalStrValue: "已编辑",
            edictModalArr: edictModalArr,
            goodsPrice: json.ResultData.NewModels.split('|')[0].split('-')[3],
            goodskucun: json.ResultData.StoreNum,
            goodsModal: json.ResultData.GoodsPrice,
            goodsBuluoPrice: json.ResultData.NewModels.split('|')[0].split('-')[2],
            // goodsKuCun: json.ResultData.StoreNum.split('|')[0].split('-')[1],
            barcode: json.ResultData.GoodsLableCode,
            kuCunReset: json.ResultData.LockGoodsStockNum,
            purChasing: json.ResultData.LimitBuyNum,
            date: json.ResultData.ExpirationTime,
          })
          if (isLockgoodsstocknum == '1') {
            disabled1 = false
            isChecked1 = true
          }

          if (isOpenlimitbuy == '1') {
            disabled2 = false
            isChecked2 = true
          }
          that.setData({
            disabled1: disabled1,
            isChecked1: isChecked1,
            disabled2: disabled2,
            isChecked2: isChecked2,
          })
        } else {
          wx.showToast({
            title: json.ResultMsg,
            icon: 'none',
            duration: 2000
          });
        }
      }
    })
  },
  // 添加兑换地址：时间选择器、早上
  morningTime0: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      morningTime: e.detail.value
    })
  },
  //添加兑换地址： 时间选择器、下午
  afternoonTime0: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      afternoonTime: e.detail.value
    })
  },
  // 修改兑换地址：时间选择器、早上
  morningTime1: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      updateMorning: e.detail.value
    })
  },
  //修改兑换地址： 时间选择器、下午
  afternoonTime1: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      updateAfternoon: e.detail.value
    })
  },
  // 
})